﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace katOS
{
    class FileManager
    {
        public volatile static Dictionary<int, string> handlersList = new Dictionary<int, string>(); //Dictionary that contains the handler and the file name
        static Dictionary<string, List<string>> filesInUse = new Dictionary<string, List<string>>(); //Dictionary that contains the file name and the file content
        static Dictionary<string, int> fileIP = new Dictionary<string, int>(); //Dictionary that contains the file name and the instruction pointer of it
        static Dictionary<string, List<int>> file_processes_list = new Dictionary<string, List<int>>(); //Dictionary that contains the file name and the list of processes that want to use it
        static int handlersCount = 1; //handlers counter


        /// <summary>
        /// Method that sets the IP of the file in use
        /// </summary>
        /// <param name="file">File name</param>
        /// <param name="ip">Instruction pointer of the file</param>
        public static void setFileIP(string file, int ip)
        {
            fileIP.Add(file, ip);
        }

        /// <summary>
        /// Method that returns the dictionary that contains the file name and the instruction pointer of it
        /// </summary>
        /// <returns>Returns a dictionary with the filename and the ip of it</returns>
        public static Dictionary<string, int> getFileIP()
        {
            return fileIP;
        }

        /// <summary>
        /// Method that adds a handler of a file to be in use to the dictionary
        /// </summary>
        /// <param name="file">The file name</param>
        public static int addHandler(string file)
        {
            handlersList.Add(handlersCount, file);
            handlersCount++;
            return handlersCount - 1;
        }

        /// <summary>
        /// Method that returns a dictionary that contains the handler and the file name
        /// </summary>
        /// <returns>Returns a dictionary with the file name and file handler</returns>
        public static Dictionary<int, string> getHandlers()
        {
            return handlersList;
        }

        /// <summary>
        /// Method that adds a file to the dictionary of files in use
        /// </summary>
        /// <param name="file">File name</param>
        /// <param name="fileContent">File Content</param>
        public static void addFileInUse(string file, List<string> fileContent)
        {
            filesInUse.Add(file, fileContent);
        }

        /// <summary>
        /// Method that returns a dictionary that contains the file name and the file content
        /// </summary>
        /// <returns>Returns a dictionary with the file name and content</returns>
        public static Dictionary<string, List<string>> getFileInUse()
        {
            return filesInUse;
        }

        /// <summary>
        /// Method that sets the  list of the processes that want to use a file
        /// </summary>
        /// <param name="file">File name</param>
        /// <param name="a_list">The processes list</param>
        public static void addFilesList(string file, List<int> a_list)
        {
            file_processes_list.Add(file, a_list);
        }

        /// <summary>
        /// Method that retutrns a dictionary that contains the file name and the list of processes that want to use it
        /// </summary>
        /// <returns>Retunrs a dictionary with the file name and a list of processes</returns>
        public static Dictionary<string, List<int>> getFileList()
        {
            return file_processes_list;
        }

    }
}
